Connecting to the Cobra Web Service Host
To use the Cobra Web Service and create applications that execute Cobra functionalities over the network, connect to the Web Service host.
The first step in using the ClientAPI is to create an instance of the CobraServices class. This is a root class that consumes the Cobra Web Service host. You can construct this class the same way you normally create an object from a class by using the new keyword.
For example:
CobraServices cobraServices = new CobraServices();Authenticating Cobra
The Cobra Web Service supports native and Windows Authentication.
Providing Cobra Username, Password, and Data Source
- Initialize an instance of SecurePassword class using a SecureString object that contains the password. Attention: For more information about SecureString class, refer to MSDN documentation.
- Initialize an instance of SecurePassword class and call the AppendChar(char) method to append each character of the password.
For example:
If Cobra is configured in a stand-alone or server-deployment environment and has multiple data sources, the data source must be specified on the ServiceIdentityData.DataSourceKey property.
cobraServices.ServiceIdentityData.Username = "SYSADMIN";
cobraServices.ServiceIdentityData.SecurePassword = new SecurePassword();
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('p');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('a');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('s');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('s');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('w');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('o');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('r');
cobraServices.ServiceIdentityData.SecurePassword.AppendChar('d');
cobraServices.ServiceIdentityData.DataSourceKey = "COBRA";Authenticating Windows
If Cobra is configured to use Windows Authentication, you do not need to supply the Cobra username and password to the ServiceIdentityData property on the instance of CobraServices class. The Cobra Web Service ClientAPI automatically transfers your Windows credentials to the Cobra Web Service host. The Cobra Web Service host uses the Windows credentials as the Cobra user.
You still need to supply the data source on the ServiceIdentityData.DataSourceKey property in the instance of CobraServices class if Cobra is configured in a stand-alone or server-deployment environment and has multiple data sources.
Calling the Login Operation to Connect to the Cobra Web Service Host
Since the CobraServices class is responsible in consuming the Cobra Web Service host, the instance of the class should be connected to the Cobra Web Service before you could perform some Cobra actions like running Advance Calendar, Calculate Progress, or Calculate Forecast. To connect to the Cobra Web Service, you must invoke the Login method.
For example:
LoginResult loginResult = cobraServices.Login();This will always be true in the current version of Cobra Web Service. The LoginResult class also contains a String property named ErrorMessage, which currently is always empty.
The Login method returns an instance of the LoginResult class that contains a Boolean property named Success. The Success property determines if the Login method succeeds. In the current version of the Cobra Web service, this will always be true. In future versions, the value of this property will identify whether the Cobra user is valid or not. The LoginResult class also contains a String property named ErrorMessage. In future versions, this will contain the error messages and the causes of validation failures.
To be compatible with future versions, Deltek recommends to check for the value of these properties before doing any Cobra actions.
For example:
if (loginResult.Success) {
// Run processes here.
}
else {
MessageBox.Show(loginResult.ErrorMessage, "Login Failed", MessageBoxButtons.Ok, MessageBoxIcons.Error)
;
}